< previous page page_281 next page >

Page 281
The LIKE function is a very powerful tool. It is covered in more depth in a later section of today's lesson, "SQL Aggregate Functions."
Using WHERE to Link Two or More Tables in a Result Set
You can use the WHERE clause to compare columns from different tables. In doing so, you can set up criteria that can link two or more tables in a single result set. The syntax for this form of the WHERE clause is
SELECT table1.columnA, table2.columnA FROM table1, table2
WHERE table1.columnA = table2.columnA
table1 and table2 are different data tables in the same database. columnA represents a single column in each of the tables. Use Visdata to enter and execute the following SQL statement. Compare your result set to the one in Figure 8.11.
SELECT Titles.Title, Publishers.Name
    FROM Publishers, Titles
   WHERE Publishers.PubID =Titles.PubID
0281-01.jpg
Figure 8.11.
Using the 
WHERE clause to link
two tables in a single result set.
The preceding SQL statement creates a result set that displays the book title and publisher's name. This is accomplished using the WHERE clause to tell SQL to select only those rows where the PubID values in each table match up. Keep in mind that this is done without any programming code, special indexing, or sorting commands. SQL handles all those tasks for you. Also, there are a few new items in this SQL statement that bear further review.
This is the first SQL statement you have encountered today that lists columns from two different tables. When selecting columns from more than one table, it is good programming practice to precede the column name with the table name and join the two with the period (.). As long as the column name is unique among all columns in the tables from which you

 
< previous page page_281 next page >

If you like this book, buy it!